﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Condition: Write a program that creates an array containing all letters
//            from the alphabet (A-Z). Read a word from the console and
//            print the index of each of its letters in the array.
    class IndexOfLetters
    {
        static void Main()
        {
            Console.Write("Write a word in capital letters: ");
            string word = Console.ReadLine();
            int wordLen = word.Length;


            char[] alphabet = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G','H','I','J','K','L', 'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };

            for (int i = 0; i < wordLen; i++)
            {
                char target = word[i];
                int lo = 0;
                int hi = alphabet.Length - 1;
                while (lo <= hi)
                {
                    int mid = (lo + hi) / 2;

                    if (alphabet[mid] == target)
                    {
                        Console.WriteLine("For letter {0}, the index in alphabet array is: {1}", target, mid);
                        break;
                    }
                    else if (alphabet[mid] < target)
                    {
                        lo = mid + 1;
                    }
                    else
                    {
                        hi = mid - 1;
                    }
                }
            }
        }
    }

